package com.sifang.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sifang.dao.MechaDao;
import com.sifang.domain.Mecha;
import com.sifang.domain.PageBean;
import com.sifang.service.IMechaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MechaServiceImpl implements IMechaService {

    @Autowired
    private MechaDao mechaDao;


    //机甲详情
    @Override
    public Mecha detail(Integer mechaId) {
        Mecha m = mechaDao.detail(mechaId);
        return m;
    }

    //机甲分页显示
    @Override
    public PageBean<Mecha> list(Integer pageNum, Integer pageSize, String sortId) {
        //创建PageBean对象
        PageBean<Mecha> pb = new PageBean<>();
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);

        List<Mecha> ms = mechaDao.list(sortId);
        Page<Mecha> p = (Page<Mecha>) ms;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }


}
